nar_color = "darkblue"
nar = codesters.Text("In this demo activity, you'll learn about a \n new way to name sprites in your programs!", 0, 150, nar_color)
nar2 = codesters.Text(" ", 0, -125, nar_color)
var_color = "orange"
def_color = "black"
str_color = "green"
num_color = "blue"
x = -150
y = -50
spacing = 30
line1_box = codesters.Rectangle(x, y, 60, 30, "whitesmoke")
line1 = codesters.Text("sprite", x, y, var_color)
line1a = codesters.Text('= codesters.Sprite( )', x +150, y, def_color)
line1b = codesters.Text(' "pig" ', x+ 233, y, str_color)
line1_box.hide()
y -= spacing
line2_box = codesters.Rectangle(x, y, 60, 30, "whitesmoke")
line2 = codesters.Text(" ", x, y, var_color)
line2a = codesters.Text(" ", x + 100, y, def_color)
line2b = codesters.Text(" ", x + 145, y, num_color)
line2_box.hide()
line3 = codesters.Text(" ", x, y, var_color)
line3a = codesters.Text(" ", x + 150, y, def_color)
line3b = codesters.Text(' ', x + 230, y, str_color)
y-= spacing
line4 = codesters.Text(" ", x, y, var_color)
line4a = codesters.Text(" ", x+105, y, def_color)
line4b = codesters.Text(' ', x + 140, y, str_color)
explain_x = -190
explain_y = 100
conn_1 = codesters.Line(explain_x + 30, explain_y, explain_x + 35, explain_y - 145, None)
exbox1 = codesters.Rectangle(explain_x, explain_y - 10, 100, 50, None)
box1_txt = codesters.Text(" ", explain_x, explain_y, nar_color)
explain_x += 120
conn_2 = codesters.Line(explain_x + 30, explain_y, explain_x + 35, explain_y - 145, None)
exbox2 = codesters.Rectangle(explain_x, explain_y - 10, 100, 50, None)
box2_txt = codesters.Text(' ', explain_x, explain_y, nar_color)
explain_x += 180
conn_3 = codesters.Line(explain_x + 50, explain_y, explain_x - 20, explain_y - 145, None)
exbox3 = codesters.Rectangle(explain_x + 25, explain_y - 10, 100, 50, None)
box3_txt = codesters.Text(' ', explain_x + 25, explain_y, nar_color)
explainer_sprites = [conn_1, exbox1, conn_2, exbox2, conn_3, exbox3]
explainer_txt = [box1_txt, box2_txt, box3_txt]
wilbur = codesters.Sprite("pig", 30, 10)
wilbur.set_size(.6)
click_rect = codesters.Rectangle(-150, 220, 200, 60, "green", "black")
click_text = codesters.Text("Click to continue", -150, 220, "white")
click_text.set_size(1.2)
top_lines = [line1, line1a, line1b, line2, line2a, line2b]
bottom_lines = [line3, line3a, line3b, line4, line4a, line4b]
def wrong_ans():
nar.set_text("Try clicking on the variable name!")
def go_on():
nar.set_text("Great! Now click Submit and Next to go on!")
count = 0
def var_click():
global count
count +=1
nar2.set_text("This is the variable name. \n We use this name to assign \n actions to sprites.")
line2.set_text('sprite')
line2a.set_text('.turn_right( )')
line2b.set_text('360')
wilbur.turn_right(360)
if count >= 3:
click_rect.show()
click_text.set_text("Click to continue.")
click_rect.event_click(click_2)
def tool_click():
global count
count += 1
nar2.set_text(' ')
for line in top_lines[3:]:
line.set_text(' ')
nar2.set_text("This is a Codesters tool. \n It creates a sprite object \n on the stage.")
if count >= 3:
click_rect.show()
click_text.set_text("Click to continue.")
click_rect.event_click(click_2)
def img_click():
global count
count += 1
nar2.set_text(' ')
for line in top_lines[3:]:
line.set_text(' ')
nar2.set_text("This is the label we use to get a certain image\n from the Codesters image library.")
if count >= 3:
click_rect.show()
click_text.set_text("Click to continue.")
click_rect.event_click(click_2)
def click_1():
stage.wait(.2)
nar.set_text("This line of code creates a sprite. \nClick on each part of the diagram to learn more.")
#sprite = codesters.Arrow(x-start, y-start, x-end, y-end, "color")
conn_1.set_color("green")
exbox1.set_color('lightblue')
box1_txt.set_text("Variable\nName")
conn_2.set_color("green")
exbox2.set_color("lightblue")
box2_txt.set_text("Codesters\nTool")
conn_3.set_color("green")
exbox3.set_color("lightblue")
box3_txt.set_text("Image\nLabel")
click_rect.hide()
click_text.set_text(' ')
exbox1.event_click(var_click)
exbox2.event_click(tool_click)
exbox3.event_click(img_click)
def click_2():
stage.wait(.2)
nar2.set_text(' ')
for line in top_lines[3:]:
line.set_text(' ')
for s in explainer_sprites:
s.hide()
for t in explainer_txt:
t.set_text(' ')
nar.set_text("We can use variables to name our sprites. Then we \ncan use the variable name to assign actions to our sprite.")
click_rect.show()
click_text.set_size(.9)
click_text.set_text("Click on the variable\n name to change it.")
line1_box.show()
line1_box.event_click(click_3)
click_rect.event_click(wrong_ans)
def click_3():
line1.set_text("wilbur")
nar.set_text("That's right!\n\n Now our sprite's name is wilbur!")
stage.wait(.2)
click_rect.hide()
click_text.set_text(" ")
nar2.set_text(' ')
tm = TestManager()
tm.display_success_message("Great job!")
click_rect.event_click(click_1)